package com.yy.glide.load;

import com.yy.glide.Key;

import java.security.MessageDigest;
import java.util.Objects;

public class ObjectKey implements Key {

    private final Object mObject;

    public ObjectKey(Object object) {
        mObject = object;
    }

    @Override
    public void updateDiskCacheKey(MessageDigest md) {
        md.update(getKeyBytes());
    }

    @Override
    public byte[] getKeyBytes() {
        return mObject.toString().getBytes();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ObjectKey objectkey = (ObjectKey) o;
        return Objects.equals(mObject, objectkey.mObject);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mObject);
    }
}
